package com.example.controller;

import com.example.pojo.Course;
import com.example.pojo.CourseLearnUnit;
import com.example.utils.Result;
import com.example.service.CourseService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/course")
@Api(value = "课程管理接口")
public class CourseController {
    @Autowired
    private CourseService courseService;

    //创建课程
    @PostMapping
    public Result addCourse(@RequestBody Course course){
        log.info("创建课程:{}"+course);
        courseService.createCourse(course);
        return Result.success();
    }
    //创建学习单元
    @PostMapping("/unit")
    public Result addUnit(@RequestBody CourseLearnUnit learnUnit){
        log.info("创建学习单元：{}"+ learnUnit);
        courseService.createUnit(learnUnit);
        return Result.success();
    }
    //查询课程
    @GetMapping
    public Result queryCourse(@RequestParam String courseName){
        Course course = courseService.queryByName(courseName);
        return Result.success(course);
    }
    //查询学习单元
    @GetMapping("/unit")
    public Result queryUnit(@RequestParam String unTitle){
        CourseLearnUnit courseLearnUnit = courseService.queryByTitle(unTitle);
        return Result.success(courseLearnUnit);
    }

}
